    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MouseSensorDriver;

import dynamixel.ComPortFindParam;
import dynamixel.ComPortFinder;
import dynamixel.HostActuator;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
import jssc.SerialPort;
import jssc.SerialPortEvent;
import jssc.SerialPortEventListener;
import jssc.SerialPortException;
import jssc.SerialPortList;
import midi.Note;
import midi.Tools;

/**
 *
 * @author root
 */
public class Tester {

    static String rs = "";
    static int[] arr;

    public static void main(String[] args) {
        //Tools.playNote(Note.p99_8_Re_Diese, Note.i98_FX_3_crystal, 127, 1000);
        ComPortFindParam cpfp = new ComPortFindParam(38400, 8, 1, 0, 16, 1000) {
            @Override
            public boolean isFinded(int[] pckg) {
                int i = 0;
                while (pckg[i] != 'R' && i < pckg.length-1) {
                    i++;
                }
                if (i == pckg.length-1) {
                    return false;
                }
                else System.out.println("R finded");
                
                i++;
                
                if (pckg[i] != '1' && pckg[i] != '2') {
                    return false;
                }
                else System.out.println("1 or 2 finded");

                if (i + 4 >= pckg.length) {
                    return false;
                }
                else System.out.println("right lenth");
                
                i++;

                if (pckg[i] != '=') {
                    return false;
                }
                else System.out.println("= finded.");

                while ((pckg[i] != 0x09 || pckg[i] != 0x0d) && i < pckg.length-1) {
                    i++;
                }

                if (pckg.length-1 == i) {
                    if(!(pckg[i] == 0x09 || pckg[i] == 0x0d)){
                        return false;
                    }
                }
                
                return true;
            }

            @Override
            public int[] getSendPckg() {
                return null;
            }
        };
        
        ComPortFinder cpf = new ComPortFinder();
        
        String s = cpf.findCom(cpfp);
        System.out.println("COM: "+s);
    }

    public static String toBinary(int val) {
        return Integer.toBinaryString(val);
    }
}
